rand: fix error check of RAND_load_file() - #1087
Merged
Merged
Conversation
rhenium
reviewed
Aug 5, 2026
| ossl_rand_load_file(VALUE self, VALUE filename) | ||
| { | ||
| if(!RAND_load_file(StringValueCStr(filename), -1)) { | ||
| if (RAND_load_file(StringValueCStr(filename), -1) <= 0) { |
Member
There was a problem hiding this comment.
Thanks for catching this. The current error check is clearly wrong: ruby -ropenssl -e'p OpenSSL::Random.load_random_file("not a file")' #=> true
Isn't a return value of 0 actually a success (indicating that the file was empty)?
Contributor
Author
There was a problem hiding this comment.
Yes, it is. I was mainly unsure whether you wanted to keep the behaviour for empty files the same as now. I think this can be argued about.
I'll drop the 0 check.
This function returns -1 on error, or the number of bytes read on success. Preserve current behaviour and also error out on error. Discovered by an experimental static analyzer I work on.
ndossche
force-pushed
the
RAND_load_file-fix
branch
from
August 5, 2026 16:18
d2c8dad to
b36a615
Compare
rhenium
approved these changes
Aug 5, 2026
Member
|
Test failure with OpenSSL master is irrelevant. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This function returns -1 on error, or the number of bytes read on success. Preserve current behaviour and also error out on error. Discovered by an experimental static analyzer I work on.